//
//  CellOfCountry.m
//  project-A (pianke)
//
//  Created by dllo on 16/2/29.
//  Copyright © 2016年 scott. All rights reserved.
//

#import "CellOfCountry.h"
#import "ModelOfCountry.h"
#import <UIImageView+WebCache.h>
#import "ViewOfCountry.h"
#import <DKNightVersion.h>
#define WIDTH  self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@interface CellOfCountry ()
@property (nonatomic, retain) UIImageView *imgBack;
@property (nonatomic, retain) UILabel *label_name_cn;

@property (nonatomic, retain) NSString *strid;


@end



@implementation CellOfCountry

-(void)dealloc{
    [_imgBack release];
    [_label_name_cn release];
   
    [_strid release];
    [super dealloc];
    
    
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
        
    }

    
    return self;
}

-(void)createViews{
    self.imgBack = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imgBack];
    [_imgBack release];
    
    self.label_name_cn = [[UILabel alloc] init];
    [self.contentView addSubview:self.label_name_cn];
    self.label_name_cn.textColor = [UIColor whiteColor];
    self.label_name_cn.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:20];
    
    [_label_name_cn release];
    
    
}

- (void)passModel:(ModelOfCountry *)model {
    NSString *str = [NSString stringWithFormat:@"%@ %@",model.name_zh_cn,model.name_en];
    self.label_name_cn.text = str;
    self.strid = model.idd;
    [self.imgBack sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:nil options:SDWebImageProgressiveDownload];
    
    self.label_name_cn.dk_textColorPicker  = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:0.64 green:0.74 blue:0.86 alpha:1]);

}
-(void)layoutSubviews{
    
    [super layoutSubviews];
    self.imgBack.frame = CGRectMake(10, 5, WIDTH - 20, (WIDTH - 20)*0.6);
    self.label_name_cn.frame = CGRectMake(20, 10, (WIDTH - 20)*0.5, 30);
    
    ViewOfCountry *view1 = [[ViewOfCountry alloc] initWithFrame:CGRectMake(10, (WIDTH - 20) * 0.6 + 5, (WIDTH - 20)/4, (WIDTH - 20) * 0.4) img:@"dengpao" title:@"攻略"];
    
    view1.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
    view1.block = ^() {
        self.block(self.strid,@"攻略");
    };
    [self.contentView addSubview:view1];
    [view1 release];
    
    ViewOfCountry *view2 = [[ViewOfCountry alloc] initWithFrame:CGRectMake(10 + (WIDTH - 20)/4, (WIDTH - 20) * 0.6 + 5, (WIDTH - 20)/4, (WIDTH - 20) * 0.4) img:@"xianlu" title:@"行程"];
    view2.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
    view2.block = ^() {
        self.block(self.strid,@"行程");
    };
    [self.contentView addSubview:view2];
    [view2 release];
    
    ViewOfCountry *view3 = [[ViewOfCountry alloc] initWithFrame:CGRectMake(10 + (WIDTH - 20)/4 * 2, (WIDTH - 20) * 0.6 + 5, (WIDTH - 20)/4, (WIDTH - 20) * 0.4) img:@"lvxing" title:@"旅行地"];
    [self.contentView addSubview:view3];
    
    view3.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
    
    view3.block = ^() {
        self.block(self.strid,@"旅行地");
    };
    
    [view3 release];
    
    ViewOfCountry *view4 = [[ViewOfCountry alloc] initWithFrame:CGRectMake(10 + (WIDTH - 20)/4 * 3, (WIDTH - 20) * 0.6 + 5, (WIDTH - 20)/4, (WIDTH - 20) * 0.4) img:@"zhuanti" title:@"专题"];
    [self.contentView addSubview:view4];
    
    view4.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
    
    view4.block = ^() {
        self.block(self.strid,@"专题");
    };
    
    [view4 release];
    

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
